package cn.com.hhrcw.service.impl;

import cn.com.hhrcw.entity.OpDeliveryHistory;
import cn.com.hhrcw.mapper.OpDeliveryHistoryMapper;
import cn.com.hhrcw.service.IOpDeliveryHistoryService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 职位-投递记录 服务实现类
 * </p>
 *
 * @author jiangdong
 * @since 2020-10-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OpDeliveryHistoryServiceImpl extends ServiceImpl<OpDeliveryHistoryMapper, OpDeliveryHistory> implements IOpDeliveryHistoryService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Integer seven(List<String> jobId) {
        if (CollectionUtils.isEmpty(jobId)) {
            return 0;
        }
        StringBuilder sql = new StringBuilder("select count(*) from op_delivery_history where DATE_SUB(CURDATE(), INTERVAL 6 DAY) <= date(create_time) and job_id in (");
        for (String id : jobId) {
            sql.append("'").append(id).append("',");
        }
        sql.deleteCharAt(sql.length() - 1);
        sql.append(")");
        return jdbcTemplate.queryForObject(sql.toString(), Integer.class);
    }

    @Override
    public Page<OpDeliveryHistory> selectResumeList(IPage page, Wrapper wrapper) {
        return this.baseMapper.selectResumeList(page, wrapper);
    }

    /**
     * 候选人列表
     *
     * @param page
     * @param wrapper
     * @return
     */
    @Override
    public Page<OpDeliveryHistory> candidateList(IPage page, Wrapper wrapper) {
        return this.baseMapper.candidateList(page, wrapper);
    }

    /**
     * 候选人列表
     *
     * @param page
     * @param param
     * @return
     */
    @Override
    public IPage<OpDeliveryHistory> resumeDeliveryList(IPage page, @Param("param") Map param) {
        return this.baseMapper.resumeDeliveryList(page, param);
    }

    /**
     * 人才库列表
     *
     * @param page
     * @param param
     * @return
     */
    @Override
    public IPage<OpDeliveryHistory> resumeTalentList(IPage page, @Param("param") Map param) {
        return this.baseMapper.resumeTalentList(page, param);
    }
}
